﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraRichEdit.Commands;
using Marmat.Foundation;

namespace Marmat.Template.WinForm
{
    public partial class CreateDataDictionaryForm : Marmat.Forms.Form
    {

        public CreateDataDictionaryForm()
        {
            InitializeComponent();
            var manager = Marmat.FrameWork.SystemCommand.GetService<Marmat.Foundation.IDataDictionaryManager>();
            List<IDataDictionaryCategory> items = new List<IDataDictionaryCategory>();
            items.Add(null);
            items.AddRange(manager.GetCategoryCollection().Where(x => x.IsGroup));
            this.comboBox1.DataSource = items;
        }

        private void comboBox1_CustomDisplayText(object sender, Forms.CustomDisplayTextEventArgs e)
        {
            if (e.Value is IDataDictionaryCategory category)
                e.DisplayText = category.Name;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if ((!string.IsNullOrEmpty(this.textBox1.Value) || this.textBox1.ReadOnly == Forms.BooleanEnum.True) && !string.IsNullOrEmpty(this.textBox2.Value))
            {
                this.DialogResult = DialogResult.OK;
            }
        }
    }
}
